﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swcommands;
using SolidWorks.Interop.swconst;
using Yuri.SolidWorks.MainFunction;

namespace Yuri.SolidWorks.Test
{
    public partial class SolidWorks功能测试 : Form
    {
        public SolidWorks功能测试()
        {
            InitializeComponent();

            //启动后展开
            FunctionTree.ExpandAll();

        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            //进行功能简要说明
            funcDescription.Text = e.Node.ToolTipText;
        }



        private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Node == null) return;

            if (e.Node.Nodes.Count != 0) return;

            #region SW主程序操作

            if (e.Node.Text == "连接SW")
            {
                if (ConnectSwApp.swApp != null)
                {
                    MessageBox.Show("连接成功！");
                }

            }

            if (e.Node.Text == "启动SW")
            {
                if (ConnectSwApp.swApp != null)
                {
                    MessageBox.Show("启动成功！");
                }

            }

            //以下代码必须启动SolidWorks执行
            if (!ConnectSwApp.GetSwApp()) return;

            if (e.Node.Text == "关闭SW")
            {

                ConnectSwApp.swApp.ExitApp();

            }

            if (e.Node.Text == "正常窗口")
            {
                ConnectSwApp.swApp.FrameState = (int)swWindowState_e.swWindowNormal;
            }

            if (e.Node.Text == "最大化")
            {

                ConnectSwApp.swApp.FrameState = (int)swWindowState_e.swWindowMaximized;
            }

            if (e.Node.Text == "最小化")
            {
                ConnectSwApp.swApp.FrameState = (int)swWindowState_e.swWindowMinimized;
            }

            if (e.Node.Text == "获取版本")
            {
                string ver = ConnectSwApp.swApp.RevisionNumber();

                var vers = ver.Split('.');

                //版本加年号1992
                MessageBox.Show($"当前版本: SOLIDWORKS {Convert.ToInt32(vers[0]) + 1992  } SP{vers[1]}");
            }

            if (e.Node.Text == "新建文件")
            {
                ConnectSwApp.swApp.RunCommand((int)swCommands_e.swCommands_New, "");
            }

            #endregion





        }
    }
}
